<script src="<?php echo $base_url?>js/jquery-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript">
function viewRef(reff) {
	window.location='index.php?ref_code='+reff;
}
function editRefCode(reff) {
	window.location='index.php?editref='+reff;
}
function addRef() {
	window.location='index.php?addref';
}

function funDelRef(refId) {
	var delPro=confirm("Are you sure want to delete this referral code?");
	if(delPro==true) {
		var frm = document.getElementById('form1');
		document.getElementById("delRef").value=refId;
		frm.submit();
	}	
}

</script>
<?php
require_once "../includes/pagination.php";

if(!empty($_POST['delRef']))
{
	$reffId=$_POST['delRef'];
	$sqlDelRef="Delete from tb1_referral_code where ref_id=$reffId";
	$rstDelRef=mysql_query($sqlDelRef);	
}
?>
<form name="form1" id="form1" method="post" action="">
<input type="hidden" name="delRef" id="delRef">
			  
<table width="100%"  border="1" cellspacing="0" class="container">
  <tr>
    <td width="469" height="25" class="tdHeader">Referral Code List&nbsp;&nbsp;<input type='button' name='add' value='Add' class="button" onclick="addRef();"></td>
  </tr>
  <tr>
    <td height="577">
	<table width="100%"  border="0" cellspacing="0">      
      <tr class="InnerHeader">       
        <td width="16%" class="line">Referral Code</td>
		<td width="14%" class="line">Post Date </td>
        <td width="8%" class="line">&nbsp;</td>
        <td width="7%" class="line">&nbsp;</td> 
		<td width="10%" class="line">&nbsp;</td>         
      </tr>
      <?php 				 
	$itemPerPage=15;
	
	$sql_shocat="SELECT * FROM tb1_referral_code";				 
	$rst_shocat=mysql_query(getPagingQuery($sql_shocat,$itemPerPage));
	$numRows = mysql_num_rows($rst_shocat);
	if($numRows>0) {				
		while($row_shocat = mysql_fetch_array($rst_shocat)) {				 
			$ref_id=$row_shocat['ref_id'];
			$ref_code=$row_shocat['ref_code'];
			$created_date=date("Y-m-d",$row_shocat['post_date']);
			echo "<tr>";
			echo "<td class='line'>$ref_code</td>";
			echo "<td class='line'>$created_date</td>";
			echo "<td height='20' class='line'><input type='button' name='edit' value='Edit' class='button' onclick='editRefCode($ref_id)'></td> ";
			echo "<td height='20' class='line'><input type='button' name='view' value='View' class='button' onclick='viewRef($ref_id)'></td> ";
			echo "<td height='20' class='line'><input type='button' name='delete' value='Delete' class='button' onclick='funDelRef($ref_id)';></td> ";
			echo "</tr>";				
		}
	}
	else {
		echo "<tr><td colspan='5' class='line'>No Referral Code found.</td></tr>";
	}				 
		?>      

	<div align="center">
		<?php		   
		   $link="members";
		   echo $disp=getPagingLink($sql_shocat,$itemPerPage,$link,$sort);							   
		?>    
	</div></table>
	</td>
 </tr>
</table></form>